﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_507_ConvertToBase7
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ConvertToBase7(-8));
            Console.ReadKey();
        }
        public static string ConvertToBase7(int num)
        {
            if (num == 0) return "0";
            Stack<int> stack = new Stack<int>();
            //取余法

            int remainder = -1;
            int n = Math.Abs(num);
            while (n != 0)
            {
                remainder = n % 7;
                stack.Push(remainder);
                n /= 7;
            }
            string str = string.Empty;
            if (num < 0) str += "-";
            foreach (var item in stack) str += item;

            return str;
        }
    }
}
